package cn.com.cym.gamezao.entity.authorize;

import cn.com.cym.gamezao.base.BaseEntity;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.springframework.lang.NonNull;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

/**
 * 权限表
 */
@ApiModel(description="权限")
@Table(name="a_authorize",uniqueConstraints=@UniqueConstraint(columnNames="code"))
@Entity
@Getter
@Setter
@Accessors(chain = true)
@NoArgsConstructor
public class Authorize extends BaseEntity implements Serializable {
    private static final long serialVersionUID = -853400553383492041L;


 /*   @JoinColumn(name = "role_id")
    @ManyToOne
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    private Role role;*/

    /**
     * code规则 package+"."+model+"."+method
     */
    @Column(length = 33)
    @ApiModelProperty(value = "权限代码",dataType = "String")
    @NonNull
    private String code;

    @Column(length = 64)
    @ApiModelProperty(value = "权限名称",dataType = "String")
    private String name;


    /**
     * 模块名称 对应的是项目名称 比如约车、核酸等
     */
    @Column(length = 64)
    @ApiModelProperty(value = "模块名称",dataType = "String")
    private String modelName;

    /**
     * 是否为菜单
     */
    @ApiModelProperty(value = "是否为菜单",dataType = "Boolean")
    private Boolean sysMenu;


    /**
     * CascadeType.DETACH
     */
    @ManyToOne(cascade = CascadeType.DETACH,fetch = FetchType.EAGER)
    @JoinColumn(name = "authorize_id")
    //@JsonIgnore
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    private Authorize authorize;


    @ApiModelProperty(value = "角色对应权限",dataType = "RoleAuthorize")
    @OneToMany(mappedBy="authorize",fetch = FetchType.LAZY,cascade = CascadeType.ALL)
    private List<Authorize> authorizes;
    /**
     * 模块代码
     */
    @Column(length = 36)
    @ApiModelProperty(value = "模块代码",dataType = "String")
    private String modelCode;
}
